#include <stdio.h>
#include <unistd.h>

#include "ohos_init.h"
#include "cmsis_os2.h"
#include "st7735s.h"

#include "lvgl.h"
#include "lv_port_disp.h"
#include "lv_port_indev.h"

#include "gui_guider.h"
#include "events_init.h"
#include "custom.h"

lv_ui guider_ui;

static void Smart_TimeKeeper_Task(void* arg)
{
    (void) arg;

    lcdInit();
    lcdClear(0xFFFF);
    lv_init();  //lvgl初始化
    lv_port_disp_init();    //lvgl屏幕驱动初始化
    lv_port_indev_init();   //lvgl输入初始化

    setup_ui(&guider_ui);   //加载UI
    events_init(&guider_ui);    //触发事件初始化
    custom_init(&guider_ui);    //自定义代码初始化
    while (1)
    {

        lv_tick_inc(5); //计时器
		lv_task_handler();  //lvgl执行函数
		usleep(5000);	
	} 
    return 0;
}

static void Smart_TimeKeeper_Entry(void)
{
    osThreadAttr_t attr;


    attr.name = "Smart_TimeKeeper_Task";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = 1024 * 20;
    attr.priority = osPriorityNormal;

    if (osThreadNew(Smart_TimeKeeper_Task, NULL, &attr) == NULL) {
        printf("[Smart_TimeKeeper_Task] Falied to create Smart_TimeKeeper_Task!\n");
    }
}

SYS_RUN(Smart_TimeKeeper_Entry);
